package it.prova.action;

import it.prova.Consts;
import it.prova.dialog.SingleNumericDialog;

import org.eclipse.jface.action.Action;
import org.w3c.dom.Element;

public class MultiDataUnitIterateAction extends Action
{
//	private Document currentModel;
	
	private Element element;
	
	public MultiDataUnitIterateAction()
	{
		setText("Iteration number");
	}
	
	/**
	 * @return Returns the element.
	 */
	public Element getElement()
	{
		return element;
	}

	/**
	 * @param element
	 *            The element to set.
	 */
	public void setElement(Element element)
	{
		this.element = element;
	}
	
	@Override
	public void run()
	{
		String value = element.getAttribute(Consts.NUMBER_ATTRIBUTE_NAME);
		
		int number = 0;
		if(value != null)
		{
			try
			{
				number = Integer.parseInt(value);
			}
			catch(NumberFormatException nfe)
			{
				
			}
		}
		
		SingleNumericDialog dialog = new SingleNumericDialog
		(
			null, 
			"Numero di iterazioni", 
			number
		);
		
		int result = dialog.open();
		System.out.println("result = " + result);			
		int selectedAttributeValue = dialog.getSelectedAttributeValue();
		System.out.println("dialog.getSelectedAttributeValue() = " + selectedAttributeValue);
		
		element.setAttribute(Consts.NUMBER_ATTRIBUTE_NAME, String.valueOf(selectedAttributeValue));
	}
}